﻿using System.Collections.Generic;
using System.ComponentModel.Composition.Hosting;
using System.Linq;

namespace OperationPlugins.Compositions
{
    public static class CompositionContainerExtensions
    {
        /// <summary>
        /// Gets the plugin.
        /// </summary>
        /// <typeparam name="T">The type of the plugin object to return.</typeparam>
        /// <returns>The plugin object, or null if not found.</returns>
        public static T GetPlugin<T>(this CompositionContainer container)
        {
            return PluginLoader.GetPlugins<T>(container).FirstOrDefault();
        }

        /// <summary>
        /// Gets all plugins.
        /// </summary>
        /// <typeparam name="T">The type of the plugin objects to return.</typeparam>
        /// <returns>Plugin objects, or an empty collection if not found.></returns>
        public static IEnumerable<T> GetPlugins<T>(this CompositionContainer container)
        {
            return PluginLoader.GetPlugins<T>(container);
        }
    }
}
